package com.wslNB.stymeleaf.controller;

import com.wslNB.stymeleaf.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

/**
 * @author wslNB
 * @createTime 2020/9/16 15:33
 * @description description
 */
@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {


    /**
     * 访问thymeleaf/hello 跳转到demo页面
     * @param model
     * @return
     */
    @RequestMapping("/hello")
    public String hello(Model model,String id){
        model.addAttribute("hello","hello thymeleaf");
        System.out.println("id值："+id);

        //list集合数据
        List<User> list = new ArrayList<>();
        list.add(new User(1,"张三","北京"));
        list.add(new User(2,"李四","上海"));
        list.add(new User(3,"王五","武汉"));
        model.addAttribute("userList",list);


        //map集合
        Map<String,String> dataMap = new HashMap<>();
        dataMap.put("NO","123");
        dataMap.put("address","北京");
        model.addAttribute("dataMap",dataMap);


        //存储一个数组
        String[] names = {"张三","张三","张三"};
        model.addAttribute("names",names);


        //日期
        model.addAttribute("date",new Date());


        //if判断
        model.addAttribute("age",22);



        return "demo";
    }

}
